<?php 
	if(!isset($_SESSION)){
		session_start();
	}

	// Clear previous messages.
	if(isset($_SESSION['table'] )) session_unregister('table');
	if(isset($_SESSION['error'])) session_unregister('error');
	if(isset($_SESSION['success'])) session_unregister('success');
	
	// Get values from the page.
	$user = $_SESSION['user'];
	$userPassword = MD5(addslashes($_POST['userPassword'])); 
	$userFullName = $_POST['userFullName'];
	$userTypeId = $_POST['userTypeId'];
	$userAddress = $_POST['userAddress'];
	$userTelephone = $_POST['userTelephone'];
	
	
	include("../dbconnection.php");
	if($userPassword != ""){
		if(mysql_query("UPDATE users SET userPassword = '$userPassword' WHERE userName='$user'")){
					$_SESSION['success'] = 'Update Successfully ';
				}else{
					$_SESSION['error'] = 'Error Occured!';
				}
	}if($userFullName != ""){
		if(mysql_query("UPDATE users SET userFullName = '$userFullName' WHERE userName='$user'")){
					$_SESSION['success'] = 'Update Successfully ';
				}else{
					$_SESSION['error'] = 'Error Occured!';
				}
	}if($userTypeId >0){
		if(mysql_query("UPDATE users SET userTypeId = '$userTypeId' WHERE userName='$user'")){
					$_SESSION['success'] = 'Update Successfully';
				}else{
					$_SESSION['error'] = 'Error Occured!';
				}
	}if($userTelephone != ""){
		if(mysql_query("UPDATE users SET userTelephone = '$userTelephone' WHERE userName='$user'")){
					$_SESSION['success'] = 'Update Successfully ';
				}else{
					$_SESSION['error'] = 'Error Occured!';
				}
	}if($userAddress != ""){
		if(mysql_query("UPDATE users SET userAddress = '$userAddress' WHERE userName='$user'")){
					$_SESSION['success'] = 'Update Successfully';
				}else{
					$_SESSION['error'] = 'Error Occured!';
				}
	}

	$_SESSION['page'] = "editUsers.php";
	header('Location: ../../');	
?>